const fs = window.require('fs');

const fileAction = {
    read: (path: string): string => {
      return fs.readFileSync(path, 'utf8');
    },
    write: (path: string, content: string, encoding: BufferEncoding): Promise<void> => {
      return fs.writeFile(path, content, { encoding: encoding || 'utf8' });
    },
    rename: (oldPath: string, newPath: string) => {
      return fs.rename(oldPath, newPath);
    },
    delete: (path: string) => {
      return fs.unlink(path);
    },
    hasFile: (path: string) => {
      return fs.access(path, fs.constants.F_OK);
    },
    canWrite: (path: string) => {
      return fs.access(path, fs.constants.W_OK);
    },
    canRead: (path: string) => {
      return fs.access(path, fs.constants.R_OK);
    },
    readDir: (path: string, encoding: BufferEncoding): Promise<string> => {
      return fs.readFile(path, { encoding: encoding || 'utf8' });
    }
  
  };
  
  export default fileAction;
  